// pages/member/book/index.js
var t = getApp(),
  e = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    route: "shop_coupon",
    menu: t.tabBar,
    menu_show: false,
    show: false,
    loaded: false,
    list: [],
    page: 1
  },
  //底部导航跳转
  menu_url: function (k) {
    e.menu_url(k, 2);
  },
  onLoad: function (options) {
    e.compatible_phonex(this);
    if (options != null && options != undefined) {
      this.setData({
        tabbar_index: options.tabbar_index ? options.tabbar_index : -1
      });
    }

    e.setting();
    this.setData({
      menu: getApp().tabBar
    })
    
    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: true,
      })
    }
    this.getList()
  },
  getList: function () {
    var t = this;
    e.get("Market/BusCoupon", {
      page: t.data.page,
      user_id: getApp().getCache("userinfo").uid
    }, function (i) {
      console.log(i)
      if (i.code == 0) {
        var a = {
          show: true
        };
        i.info.length > 0 && (a.page = t.data.page + 1, a.list = t.data.list.concat(i.info), i.info.length < 10 && (a.loaded = true)),//concat() 方法用于连接两个或多个数组。
          i.info.length == 0 && (a.loaded = true);
        t.setData(a)
      } else {
        e.alert(i.msg)
      }
    }, true)
  },
  /**
  *上拉加载
  */
  onReachBottom: function () {
    this.data.loaded || this.getList()
  },

  /**
   *下拉刷新
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      list: [],
      loaded: false
    }),
    this.getList()
    wx.stopPullDownRefresh()
  },
  /**
     *领券
     * @return string
     */
  getCoupon: function (t) {
    var that = this,
      s = e.pdata(t);
    e.get("Market/GetCoupon", {
      coupon_id: s.id,
      end_time:s.endtime,
      user_id: getApp().getCache("userinfo").uid
    }, function (i) {
      0 == i.code ? (
        e.alert('领券成功', function () {
          that.setData({
            page: 1,
            list: []
          }),
            that.getList()
        })
      ) : e.alert(i.msg)
    })

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})